<?php
namespace Home\Controller;
use Think\Controller;
class LogisticsController extends Controller {
    public function _initialize()
    {
        //自动加载的类
        new \Org\Autoload();
        $this->member_id = $this->member_info['member_id'];
        //echo $this->member_id;exit;
    }
    //首页
    public function index(){
        $data['title']='找物流 找金银网';
        $data['active']='logistics';
        $this->assign("data", $data);
        $this->display();
    }
    public function result(){
        if(!I('post.typeNu')||!I('post.typeCom')){
            echo "<script>alert('请您填写完整后再提交，谢谢');history.back(-1);</script>";exit;
        }
        $typeCom=I('post.typeCom');//快递公司
        $typeNu=I('post.typeNu');  //快递单号
        //$typeCom='tiantian';//快递公司
        //$typeNu='550292847690';  //快递单号
        //echo $typeCom.'<br/>' ;
        //echo $typeNu ;
        $AppKey='1ae24a144ff2b2be';//请将XXXXXX替换成您在http://kuaidi100.com/app/reg.html申请到的KEY
        $url ='http://api.kuaidi100.com/api?id='.$AppKey.'&com='.$typeCom.'&nu='.$typeNu.'&show=2&muti=1&order=asc';
        //请勿删除变量$powered 的信息，否者本站将不再为你提供快递接口服务。
        $powered = '查询数据由：<a href="http://kuaidi100.com" target="_blank">KuaiDi100.Com （快递100）</a> 网站提供 ';
        //优先使用curl模式发送数据
        if (function_exists('curl_init') == 1){
            $curl = curl_init();
            curl_setopt ($curl, CURLOPT_URL, $url);
            curl_setopt ($curl, CURLOPT_HEADER,0);
            curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt ($curl, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
            curl_setopt ($curl, CURLOPT_TIMEOUT,5);
            $get_content = curl_exec($curl);
            curl_close ($curl);
        }else{
            echo '不支持curl，请联系网站系统管理员，谢谢';exit;
            include("snoopy.php");
            $snoopy = new snoopy();
            $snoopy->referer = 'http://www.google.com/';//伪装来源
            $snoopy->fetch($url);
            $get_content = $snoopy->results;
        }
        //dump($get_content);exit;
        //print_r($get_content . '<br/>' . $powered);exit;

        $data['title']='找物流 找金银网';
        $data['active']='logistics';
        $this->assign("data", $data);
        $this->assign("get_content", $get_content);
        $this->assign("powered", $powered);
        $this->display();
    }

    //提交留言
    public function message_add_post() {
        if(!$this->member_id){
            echo "<script>alert('请您登录后再提交查询');window.location.href='/user/login';</script>";exit;
        }
        $post=I('post.');
        if (!$post['load_area']||!$post['unload_area']||!$post['goods']||!$post['weight']) {
            echo "<script>alert('提交信息信息不完整，请您填写完整后再提交');history.back(-1);</script>";exit;
        }
        $post['member_id']=$this->member_id;
        $post['add_time']=time();
        //print_r($post);exit;
        $Model=D("LogisticsMessage");
        $Model->post=$post;
        if(!$Model->message_add_post()){
            echo "<script>alert('提交失败，请您尝试重新提交');history.back(-1);</script>";exit;
        }
        echo "<script>alert('提交成功');history.back(-1);</script>";
    }

}